package com.wnhz.work.jy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wnhz.work.jy.R;
import com.wnhz.work.jy.bean.ChooseAddressBean;

import java.util.List;

/**
 * Created by Administrator on 2016/9/9 0009.
 */
public class ChooseAddressAdapter extends BaseAdapter {
    private static final String TAG = "ChooseAddressAdapter";
    private Context context;
    private List<ChooseAddressBean> chooseLise;
    private View.OnClickListener listener;
    private boolean isHas;

    public ChooseAddressAdapter(Context context, List<ChooseAddressBean> chooseLise, View.OnClickListener listener) {
        this.context = context;
        this.chooseLise = chooseLise;
        this.listener = listener;
    }

    @Override
    public int getCount() {
        return chooseLise.size();
    }

    @Override
    public Object getItem(int position) {
        return chooseLise.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ChooseViewHolder viewHolder = new ChooseViewHolder();
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.choose_address_item, null);
            viewHolder.rl_choose_true = (RelativeLayout) convertView.findViewById(R.id.rl_choose_true);
            viewHolder.iv_choose = (ImageView) convertView.findViewById(R.id.iv_choose);
            viewHolder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);//姓名
            viewHolder.tv_phone = (TextView) convertView.findViewById(R.id.tv_phone);//电话
            viewHolder.tv_address = (TextView) convertView.findViewById(R.id.tv_address);//地址
            viewHolder.tv_compile = (TextView) convertView.findViewById(R.id.tv_compile);//编辑

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ChooseViewHolder) convertView.getTag();
        }
        viewHolder.tv_name.setText(chooseLise.get(position).getName());
        viewHolder.tv_phone.setText(chooseLise.get(position).getPhone());

        String getCity = chooseLise.get(position).getCitys();
        String getArea = chooseLise.get(position).getAreas();
        String getDoorplate = chooseLise.get(position).getAddress();

        viewHolder.tv_address.setText(getCity + getArea + getDoorplate);

        if (chooseLise.get(position).isSelect() == true) {
            viewHolder.iv_choose.setImageResource(R.mipmap.ic_xuanze31_li);
        } else {
            viewHolder.iv_choose.setImageResource(R.mipmap.ic_xuanze_nor);
        }

        viewHolder.rl_choose_true.setOnClickListener(listener);
        viewHolder.rl_choose_true.setTag(position);
        viewHolder.tv_compile.setOnClickListener(listener);
        viewHolder.tv_compile.setTag(position);

        return convertView;
    }

    //  删除数据
    public void removeData(int position) {
        chooseLise.remove(position);
        notifyDataSetChanged();
    }

    class ChooseViewHolder {
        RelativeLayout rl_choose_true;
        ImageView iv_choose;
        TextView tv_name;
        TextView tv_phone;
        TextView tv_address;
        TextView tv_compile;

    }
}
